//
//  HOTMessageBoxCell.m
//  Genpara
//
//  Created by AndyChang.zhang on 14-9-11.
//  Copyright (c) 2014年 zhangchh. All rights reserved.
//

#import "HOTMessageBoxCell.h"

@implementation HOTMessageBoxCell

- (void)awakeFromNib
{
    mailBoxImage = [UIImage imageNamed:@"icon_mail"];
    mailBoxOpenImage = [UIImage imageNamed:@"icon_mailopen"];
    mailAnswerImage = [UIImage imageNamed:@"icon_mailanswer"];
    mailSendImage = [UIImage imageNamed:@"icon_send"];
    
    _checkBtn.frame = CGRectMake(_checkBtn.frame.size.width *-1, _checkBtn.frame.origin.y, _checkBtn.frame.size.width, _checkBtn.frame.size.height);
    
    mailBoxDefaultFrame = mailStutasImageView.frame;
    mailBoxOpenFrame = CGRectMake(mailBoxDefaultFrame.origin.x, (self.frame.size.height - 35)/2, 30, 35);
    mailAnswerBoxFrame = CGRectMake(ZZZ_calcX(mailStutasImageView, 0) - 54, (self.frame.size.height - 30)/2, 54, 30);
    mailSendFrame = mailBoxDefaultFrame;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    
}

-(void)setEdit:(BOOL)flg animated:(BOOL)animated{
    
    isEdit = flg;
    
    if (flg) {
        
        if (animated) {
            
            [UIView animateWithDuration:0.3 animations:^{
                
                _checkBtn.frame = CGRectMake(10, _checkBtn.frame.origin.y, _checkBtn.frame.size.width, _checkBtn.frame.size.height);
                
                self.dateTimeLabel.frame = CGRectMake(44, self.dateTimeLabel.frame.origin.y, self.dateTimeLabel.frame.size.width, self.dateTimeLabel.frame.size.height);
                
                self.titleLabel.frame = CGRectMake(44, self.titleLabel.frame.origin.y, 218, self.titleLabel.frame.size.height);
            }];
        } else {
            
            _checkBtn.frame = CGRectMake(10, _checkBtn.frame.origin.y, _checkBtn.frame.size.width, _checkBtn.frame.size.height);
            
            self.dateTimeLabel.frame = CGRectMake(44, self.dateTimeLabel.frame.origin.y, self.dateTimeLabel.frame.size.width, self.dateTimeLabel.frame.size.height);
            
            self.titleLabel.frame = CGRectMake(44, self.titleLabel.frame.origin.y, 218, self.titleLabel.frame.size.height);
        }
        
        
    } else {
        
        if (animated) {
            
            [UIView animateWithDuration:0.3 animations:^{
                
                _checkBtn.frame = CGRectMake(_checkBtn.frame.size.width *-1, _checkBtn.frame.origin.y, _checkBtn.frame.size.width, _checkBtn.frame.size.height);
                
                self.dateTimeLabel.frame = CGRectMake(11, self.dateTimeLabel.frame.origin.y, self.dateTimeLabel.frame.size.width, self.dateTimeLabel.frame.size.height);
                
                self.titleLabel.frame = CGRectMake(11, self.titleLabel.frame.origin.y, 251, self.titleLabel.frame.size.height);
            }];
        } else {
            
            _checkBtn.frame = CGRectMake(_checkBtn.frame.size.width *-1, _checkBtn.frame.origin.y, _checkBtn.frame.size.width, _checkBtn.frame.size.height);
            
            self.dateTimeLabel.frame = CGRectMake(11, self.dateTimeLabel.frame.origin.y, self.dateTimeLabel.frame.size.width, self.dateTimeLabel.frame.size.height);
            
            self.titleLabel.frame = CGRectMake(11, self.titleLabel.frame.origin.y, 251, self.titleLabel.frame.size.height);
        }
    }
}

- (IBAction)checkBtnClicked:(UIButton *)sender {
    
    sender.selected = !sender.isSelected;
    
    if ([self.delegate respondsToSelector:@selector(selectedItem:indexPath:)]) {
        
        [self.delegate selectedItem:_checkBtn.isSelected indexPath:self.indexPath];
    }
}

-(void)setMailStatus:(NSString *)status {
    

    switch ([status intValue]) {
        case 1: //未读
            mailStutasImageView.image = mailBoxImage;
            mailStutasImageView.frame = mailBoxDefaultFrame;
            break;
        case 2://已读
//            mailStutasImageView.image = mailAnswerImage;
//            mailStutasImageView.frame = mailAnswerBoxFrame;
            mailStutasImageView.image = mailBoxOpenImage;
            mailStutasImageView.frame = mailBoxOpenFrame;
            break;
        case 3://已回复
            mailStutasImageView.image = mailAnswerImage;
            mailStutasImageView.frame = mailAnswerBoxFrame;
            break;
        default://已发送
            mailStutasImageView.image = mailSendImage;
            mailStutasImageView.frame = mailSendFrame;
            break;
    }
}

-(void)setSelectedItem:(BOOL)selected {
    
    _checkBtn.selected = selected;

}

@end
